package com.baoyouqun.controller.weixin;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.Response;
import com.baoyouqun.domain.CreateCmd.DemandInteractCreateCmd;
import com.baoyouqun.domain.UpdateCmd.DemandInteractUpdateCmd;
import com.baoyouqun.service.DemandInteractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx/demand/interact")
@Api(tags = "需求互动（点赞/点踩）管理接口")
public class WxDemandInteractController {

    @Resource
    private DemandInteractService demandInteractService;

    @PostMapping("operate")
    @ApiOperation("点赞/点踩操作（1-点赞，-1-点踩）")
    public Response operate(@Valid @RequestBody DemandInteractCreateCmd cmd) {
        String userId = StpUtil.getLoginIdAsString();
        cmd.setUserId(userId);
        return demandInteractService.operate(cmd);
    }

    @PutMapping("cancel")
    @ApiOperation("取消点赞/点踩")
    public Response cancel(@Valid @RequestBody DemandInteractUpdateCmd cmd) {
        String userId = StpUtil.getLoginIdAsString();
        return demandInteractService.cancel(cmd.getDemandId(), userId);
    }


}